Key-Value Database
In this lesson, you will understand the key-value database and when to choose it for your projects.
What is a key-value database?#
Key-value databases are also a part of the NoSQL family. These databases use a simple key-value pairing method to store and quickly fetch the data with minimum latency.
Features of a key-value database#
Due to the minimum latency they ensure, that is constant O(1) time, the primary use case for these databases is caching application data.
The key serves as a unique identifier and has a value associated with it. The value can be as simple as a string and as complex as an object graph.
The data in key-value databases can be fetched in constant time O(1), and there is no query language required to fetch the data. It’s just a simple no-brainer fetch operation. This ensures minimum latency.
As discussed earlier in the course, these databases are also used to achieve a consistent state in distributed systems.
Popular key-value databases#
Some of the popular key-value data stores used in the industry are Redis, Hazelcast, Riak, Voldemort, and Memcached.
When do I pick a key-value database?#
If you have a use case where you need to fetch data real fast with minimum fuss, you should pick a key-value datastore.
Key-value stores are built to serve use cases that require super-fast data fetch.
Typical use cases of a key-value database are:
- Caching
- Persisting user state
- Persisting user sessions
- Managing real-time data
- Implementing queues
- Creating leaderboards in online games and web apps
- Implementing a pub-sub system
Real-life implementations#
Here are some of the real-life implementations of the tech:
- Inovonics uses Redis to drive real-time analytics on millions of sensor data.
- Microsoft uses Redis to handle the traffic spike on its platforms
- Google Cloud uses Memcached to implement caching on their cloud platform.